package cn.maihe.elg.operation.centers.supports;

import cn.maihe.elg.operation.model.enums.CenterNoEnum;
import com.google.common.collect.Maps;
import io.jsonwebtoken.lang.Assert;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author WJH
 * @Date 2021/05/27
 */
@Component
public class CenterInterfaceServiceFactory {
    private static final Map<CenterNoEnum, CenterInterfaceService> centerMap = Maps.newHashMap();

    public CenterInterfaceServiceFactory(List<CenterInterfaceService> centerInterfaceServiceList) {
        centerInterfaceServiceList.forEach(s -> {
            centerMap.put(s.getCenterNoEnum(), s);
        });
    }

    public static CenterInterfaceService getByCenterNoEnum(CenterNoEnum centerNoEnum) {
        CenterInterfaceService centerInterfaceService = centerMap.get(centerNoEnum);
        Assert.notNull(centerInterfaceService, "查无此中心实现类：" + centerNoEnum);
        return centerInterfaceService;
    }

}
